package jq.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jq.dao.IEntityManagerImpl;
import jq.entity.Currency;

public class LoadCurrency extends HttpServlet {
	private static final long serialVersionUID = 7837521939670277448L;

	@SuppressWarnings("unchecked")
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int count=IEntityManagerImpl.getInstance().queryEntityCount(Currency.class);
		if(count==0){
			req.getSession().setAttribute("result", "no currency available in datastore");
		}else{
			List<Currency> list=(List<Currency>) IEntityManagerImpl.getInstance().queryAllEntity(Currency.class);
			req.getSession().setAttribute("currency", list);
			req.getSession().setAttribute("result", "load currency success");
		}
		resp.sendRedirect("currency.jsp");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}
	
}
